package com.ang.function;

import lombok.Data;

import java.util.function.Function;

public class FunctionTest {
        public static void main(String[] args) {
            new FunctionTest().test();
            System.out.println("--------------------");
            new FunctionTest().test1();
        }

        public void test() {
            Function<Numbers, Integer> test1 = i -> i.getN1() - i.getN2();
            Function<Numbers, Integer> test2 = i -> i.getN1() * i.getN2();
            System.out.println(calculate(test1, 111, 5));
            System.out.println(calculate(test2, 111, 5));
        }

        public static Integer calculate(Function<Numbers, Integer> test, Integer number1, Integer number2) {
            Numbers n = new Numbers();
            n.setN1(number1);
            n.setN2(number2);
            return test.apply(n);
        }
//===============================================================================================================
        public void test1(){
            Numbers numbers = new Numbers();
            numbers.setN1(111);
            numbers.setN2(5);

            System.out.println(FunctionInterface.func1.apply(numbers));
            System.out.println(FunctionInterface.func2.apply(numbers));
        }
    }

@Data
class Numbers {
    private Integer n1;
    private Integer n2;
    private Integer n3;
}

interface FunctionInterface{
    Function<Numbers, Integer> func1 = numbers -> numbers.getN1() - numbers.getN2();
    Function<Numbers, Integer> func2 = numbers -> numbers.getN1() * numbers.getN2();
}
